[contents] [prev] [next] [top] [bottom] (4 out of 5)

Retrieving Information about the Exception

Script uses two global variables to record information about the most recently reported exception:

To print the format string associated with the most recently reported exception, use the following call to the prin method:

 prin throwTag throwArg debug

The exception classes specialize the prin generic function. (Recall that print, prinln, format, and the other global printing functions are derived from the generic prin, as discussed in the section on "Output" on page 72.) On most objects, the prin method takes three arguments: the object to print, a style argument, and an optional stream. In the case of exception objects, the second argument can be one of the following:

When prin is called on an exception with a second argument of throwArg, it prints the format string for the exception. The global variable throwTag is always bound to the most recently reported exception.

To retrieve the information that the most recently reported exception received from report, get the value of the global variable throwArg.

The following example shows the use of throwArg and throwTag. Note that the prinln function does the same thing as prin, but adds a newline at the end of the printed output.

global a1:88, b1:0, c1, d1, e1
guard (
c1 := a1 / b1
d1 := a1 - b1
e1 := a1 / c1
)
catching
	divideByZero returnArg: (
		format debug "The number divided by 0 is: %*\n" throwArg @normal
		prin "The default error message is:\n" @unadorned debug
		prinln throwTag throwArg
		caught undefined
	)
end

This script, upon attempting to divide 88 by 0, catches the divideByZero error and prints the following messages to the debugging stream:

The number divided by 0 is: 88
The default error message is:
Attempt to divide 88 by zero. (DivideByZero)


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.